﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using  ZebraCoreLib.Framework;
using System.Data.Linq.Mapping;
using ZebraCoreLib.ZebraException;
using ZebraCoreLib.BasBiz;
using System.Data.Common;
using ZebraCoreLib.Stock;
using ZebraCoreLib.Logistics;

namespace ZebraCoreLib.Notice
{
    /// <summary>
    /// 预报明细
    /// </summary>
    [ZebraBizObject(TableName = "osShipNoticeDetail")]
    public class NoticeDetails:BasBizService<NoticeDetails>
    {
        [ZebraField(Title = "编号",DataField="ID", MaxSize = 32, IsRequired = true, IsAutoID = true)]
        public string ID { get; set; }
        [ZebraField(Title = "预报编号", DataField = "NoticeID", MaxSize = 32, IsRequired = true)]
        public string NoticeID { get; set; }
        [ZebraField(Title = "SKU号码", DataField = "SKU", MaxSize = 32, IsRequired = true,WaterMark = "请输入SKU")]
        public string SKU { get; set; }
        [ZebraField(Title = "商品名称", DataField = "GoodsName",WaterMark = "请输入商品名称")]
        public string GoodsName { get; set; }
        [ZebraField(Title = "数量", DataField = "Qty", IsRequired = true)]
        public int Qty { get; set; }
        [ZebraField(Title = "入库ID", DataField = "sgID")]
        public string sgID { get; set; }
        [ZebraField(Title="入库信息",Relationship="sgid=sgid")]
        public GoodsStock Stock { get; set; }
    }

    public enum NoticeStatus
    {
        PreInStock=0,
        InStock=1
    }
 
    /// <summary>
    /// 预报
    /// </summary>
    [ZebraBizObject(TableName = "osShipNotice")]
    public class Notice:BasBizService<Notice>
    {
        [ZebraField(Title = "编号", DataField="ID", MaxSize = 32,IsRequired=true,IsAutoID=true,IsPrimaryKey=true)]
        public string ID {get;set;}

        [ZebraField(Title = "客户编号", DataField = "suCode", MaxSize = 32, IsRequired = true)]
        public string suCode{get;set;}

        [ZebraField(Title = "仓库",DataField = "sgArea", MinSize = 3, MaxSize = 3, IsRequired = true, WaterMark = "请选择仓库", ToolTip = "如何开通仓库？")]
        public string sgArea { get; set; }

        [ZebraField(Title = "转运单号", DataField = "seCode", MinSize = 8, UserScopeKey = true, MaxSize = 32, IsRequired = true, WaterMark = "请输入转运单号")]
        public string seCode { get; set; }

        [ZebraField(Title = "转运公司", DataField = "seExpress", MaxSize = 32)]
        public string seExpress { get; set; }

        [ZebraField(Title = "状态", DataField = "seState")]
        public NoticeStatus seState { get; set; }

        [ZebraField(Title = "提供商",DataField = "Vendor")]
        public string Vendor { get; set; }

        [ZebraField(Title = "预报时间", DataField = "OpTime",SortOrder=true, SortByDesc=true)]
        public DateTime OpTime { get; set; }

        [ZebraField(Title = "订单号",DataField = "PONO")]
        public string PONO{get;set;}
       // private List<NoticeDetails> m_noticeDetails = new List<NoticeDetails>();

        [ZebraField(Title = "预报明细", Foreignkey = "NoticeID")]
        public List<NoticeDetails> NoticeDetails{get; set;}

        [ZebraField(Title = "入库ID", DataField = "sgID")]
        public string sgID { get; set; }
        [ZebraField(Title = "入库信息", Relationship = "sgid=sgid")]
        public GoodsStock Stock { get; set; }

        [ZebraField(Title = "仓库信息", Relationship = "sacode=sgArea")]
        public  LogisticsCenter LogisticsCenterArea { get; set; }
         

        public Notice()
        {
            //SubmitSecode=seCode.Length>=8 && 
        }

      
        public override Notice Add(Notice entity)
        {

            Transation = SQLHelper.BeginTransaction();
       
            try 
            {
                base.Add(entity);
                SQLHelper.Commit(Transation);
                //Transation.Connection.Close();
            }
            catch (Exception ex)
            {
                SQLHelper.Rollback(Transation);
                //Transation.Connection.Close();
                throw ex;
            }
            return entity;

        }

        public List<Notice> List(string sucode, string area, NoticeStatus status, DateTime beginData, DateTime endDate)
        {
            return List("suCode='" + sucode + "' and sgarea='" + area + "'");
        }
        public List<Notice> List(string sucode, string area, NoticeStatus status, DateTime beginData, DateTime endDate, int pageIndex, int pageSize, out int pageCount)
        {
           
            pageCount = 0;
            return List("suCode='" + sucode + "' and sgarea='" + area + "'");
        }
        
    }


}
